using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace Controls
{
	public class TextBoxHideEdit : TextBoxEx
	{
		public static readonly DependencyProperty DefaultTextProperty;

		public string DefaultText
		{
			get
			{
				return (string)GetValue(DefaultTextProperty);
			}
			set
			{
				SetValue(DefaultTextProperty, value);
			}
		}

		static TextBoxHideEdit()
		{
			DefaultTextProperty = DependencyProperty.Register("DefaultText", typeof(string), typeof(TextBoxHideEdit), new PropertyMetadata("Text"));
			FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBoxHideEdit), new FrameworkPropertyMetadata(typeof(TextBoxHideEdit)));
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
		}

		protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
		{
			base.OnMouseDoubleClick(e);
			base.Background = new SolidColorBrush(Colors.White);
			base.BorderThickness = new Thickness(1.0);
			Focus();
		}

		protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
		{
			base.OnPreviewLostKeyboardFocus(e);
			if (string.IsNullOrEmpty(base.Text))
			{
				base.Text = DefaultText;
			}
			base.Background = new SolidColorBrush(Colors.Transparent);
			base.BorderThickness = new Thickness(0.0);
		}
	}
}
